import random


def checkIntList(intList: list) -> str:
    for operator0 in ["", "-"]:
        for operator1 in "+-*/":
            for operator2 in "+-*/":
                for operator3 in "+-*/":
                    caseString = "{:s}{:d}{:s}{:d}{:s}{:d}{:s}{:d}".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}({:d}{:s}{:d}){:s}{:d}{:s}{:d}".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}({:d}{:s}{:d}{:s}{:d}){:s}{:d}".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}(({:d}{:s}{:d}){:s}{:d}){:s}{:d}".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}({:d}{:s}({:d}{:s}{:d})){:s}{:d}".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}{:d}{:s}({:d}{:s}{:d}){:s}{:d}".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}{:d}{:s}({:d}{:s}{:d}{:s}{:d})".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}{:d}{:s}(({:d}{:s}{:d}){:s}{:d})".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}{:d}{:s}({:d}{:s}({:d}{:s}{:d}))".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}{:d}{:s}{:d}{:s}({:d}{:s}{:d})".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
                    caseString = "{:s}({:d}{:s}{:d}){:s}({:d}{:s}{:d})".format(
                        operator0, intList[0], operator1, intList[1], operator2, intList[2], operator3, intList[3])
                    if checkString(caseString):
                        return caseString
    return None


def checkString(caseString: str) -> bool:
    try:
        caseResult = eval(caseString)
        if caseResult == 24:
            return True
        else:
            return False
    except ZeroDivisionError:
        return False


if __name__ == "__main__":
    randomIntList = [random.randint(1, 10) for _ in range(4)]
    print(randomIntList)
    result = checkIntList(randomIntList)
    if result is None:
        print("Failed!")
    else:
        print("{:s}=24".format(result))
